﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WITM.DAL;

namespace WITM.BLL
{
    public class UserBL
    {
        private IUnitOfWork unitOfWork;

        public UserBL(IUnitOfWork unitOfWork)
        {
            this.unitOfWork = unitOfWork;
        }

        public IEnumerable<Users> GetAll()
        {
            return unitOfWork.UserRepository.GetAll();
        }

        public Users GetUserByID(int ID)
        {
            return unitOfWork.UserRepository.First(u => u.UserID == ID);
        }

        public void Add(Users user)
        {
            Users checkUser = unitOfWork.UserRepository.First(u => u.UserName == user.UserName);
            if (checkUser == null)
            {
                unitOfWork.UserRepository.Add(user);
                unitOfWork.Commit();
            }
            else
            {
                throw new Exception("User with specific username already exists");
            }
        }

    }
}
